﻿package bdz.projects.lavender.opsm.vo {
	import bdz.common.display.DisplayLoader;
	import flash.events.Event;
	import flash.events.EventDispatcher;
	import flash.utils.Dictionary;
	
	/**
	 * ...
	 * @author Donald
	 */
	public class ProductVO extends EventDispatcher {
		
		private var source:XML;
		public var index:Number;
		public function ProductVO(_defXML:XML) {
			source = _defXML;
		}
		public function get date():Date {
			if(source.date != null && source.date.toString() != ""){
				var dstring:String = source.date.toString();
				var darr:Array = dstring.split("/");
				return new Date(darr[2], Number(darr[1]) - 1, darr[0]);
			}
			return new Date();
		}
		
		public function get time():Number {
			return date.getTime();
		}
		public function get productID():String {
			return source.@id.toString();
		}
		public function get sku():String {
			return source.@sku.toString();
		}
		public function get topLevelID():String {
			return source.@top_level_id.toString();
		}
		public function get title():String {
			return source.title.toString();
		}
		public function get description():String {
			return source.description.toString();
		}
		public function get price():Number {
			return Number(source.price.toString());
		}
		public function get color():String {
			return source.color.toString();
		}
		public function get colorHex():Number {
			return Number(source.color_hex.toString());
		}
		public function get brandID():String {
			return source.brand.@id.toString();
		}
		public function get brandName():String {
			return source.brand.title.toString();
		}
		public function get brandImage():String {
			return source.brand.image.toString();
		}
		public function get defaultImage():String {
			return "http://www.badongers.com/lab/BigAssImage2.jpg?new="+index;
			try{
				return source.images.image[0].toString();
			}catch (e:Error) {} 
			
		}
		public function get allImages():Array {
			var ret:Array = new Array();
			var xlist:XMLList = source.images.image;
			for each(var xm:XML in xlist) {
				ret.push(xm.toString());
			}
			return ret;
		}
		public function isTypeOf(title:String, type:String):Boolean {
			var xlist:XMLList = source.types.tag;
			for each(var xm:XML in xlist) {
				if (xm.@title.toString() == title && xm.@type.toString() == type) {
					return true;
				}
			}
			return false;
		}
		public function clear():void {
			
		}
	}
	
}